package com.jishuo.pzk.service;

import com.github.pagehelper.PageHelper;
import com.jishuo.pzk.bean.base.PzmsgVO;
import com.jishuo.pzk.fsdao.PzmessageMapper;
import com.jishuo.pzk.util.VoucherUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@Service
public class PzmessageService {
    @Resource
    PzmessageMapper pzmessageMapper;
    @Resource
    private EticketNumService eticketNumService;
    @Resource
    private StudentService studentService;
    @Resource
    private BackBillService backBillService;
    @Resource
    private FiscService fiscService;
    @Resource
    private BalanceService balanceService;
    @Resource
    private WaitAffirmService waitAffirmService;
    @Resource
    private DivideService divideService;
    @Resource
    private SpecialService specialService;
    @Resource
    private IllegalActivityService illegalActivityService;
    @Resource
    private DeductService deductService;
    @Resource
    private WaitAffirmPayInfoService waitAffirmPayInfoService;
    @Resource
    private IllegalActivityScaleInfoService illegalActivityScaleInfoService;
    @Resource
    private ChargeBillService chargeBillService;
    @Resource
    private VoucherUtil voucherUtil;

    /**
     * 导入数据
     */
    public void impData() {
        List<PzmsgVO> list = this.listPzmsg();
        int n = 0;
        for (PzmsgVO vo : list) {
            String action = vo.getAction();
            String data = vo.getData();
            int ret = 0;
            // 根据不同的action调用相应的服务保存数据
            if ("SETETICKETPZK".equals(action)) {
                ret = eticketNumService.savePzk(data); // 电子票
            } else if ("SETSTUDENTPZK".equals(action)) {
                ret = studentService.savePzk(data); // 学生票
            } else if ("SETBACKBILLPZK".equals(action)) {
                ret = backBillService.savePzk(data); // 退付书
            } else if ("SETBANKPAYFISCPZK".equals(action)) {
                ret = fiscService.savePzk(data); // 国库
            } else if ("SETBANKBALANCEPZK".equals(action)) {
                ret = balanceService.savePzk(data); // 余额
            } else if ("SETWAITAFFIRMPZK".equals(action)) {
                ret = waitAffirmService.savePzk(data); // 待查收入
            } else if ("SETPAYDIVIDEPZK".equals(action)) {
                ret = divideService.savePzk(data); // 分成
            } else if ("SETSPECIALPZK".equals(action)) {
                ret = specialService.savePzk(data); // 专户
            } else if ("SETPAYINFOPZK".equals(action)) {
                ret = illegalActivityService.savePzk(data); // 交罚
            } else if ("SETDEDUCTPZK".equals(action)) {
                ret = deductService.savePzk(data); // 批扣
            } else if ("SETWAITAFFIRMPAYINFOPZK".equals(action)) {
                ret = waitAffirmPayInfoService.savePzk(data); // 待查支出
            } else if ("SETBANKILLEGALACTIVITYSCALEINFOPZK".equals(action)) {
                ret = illegalActivityScaleInfoService.savePzk(data); // 交管二八分成
            } else if ("SETCHARGEBILLPZK".equals(action)) {
                ret = chargeBillService.savePzk(data); // 缴款书
            } else if ("SETVOUCHERELIMINATION".equals(action)) {
                ret = voucherUtil.voucherElimination(data); // 凭证冲销
            }

            // 判断返回值ret是否大于0
            if (ret > 0) {
                // 如果大于0，更新数据id的状态
                this.pzmessageMapper.updateState(vo.getDataId());
                n++; // 更新操作计数
            }
        }
        log.info("导入数据：{}条", n);
    }

    /**
     * 列出Pzmsg信息列表。
     *
     * 本方法不接受任何参数，主要执行以下操作：
     * 1. 使用PageHelper进行分页设置，起始页为1，每页显示500条记录。
     * 2. 调用pzmessageMapper的listPzmsg方法获取Pzmsg信息列表。
     *
     * @return 返回一个包含PzmsgVO对象的List列表。
     */
    public List<PzmsgVO> listPzmsg() {
        // 使用PageHelper进行分页设置
        PageHelper.startPage(1, 500);
        // 调用mapper层方法获取Pzmsg信息列表
        return pzmessageMapper.listPzmsg();
    }
}
